package com.chaosj.webmagic.dto.idiomschina;

import com.chaosj.webmagic.dto.SearchResponseDto;
import com.google.common.base.Splitter;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @className: LexiconResponseDto
 * @description:
 * @author: caoyangjie
 * @date: 2021/8/12
 **/
public class LexIconResponseDto extends SearchResponseDto {

    @Override
    public void addObject(String... args) {
        list.add(new LexIconContent(args[0],args[1],args[2],args[3]));
    }

    @Data
    @Accessors(chain = true)
    @AllArgsConstructor
    class LexIconContent {
        private String title;
        private String target;
        private String source;
        private String content;

        @Override
        public String toString(){
            StringBuffer stringBuffer = new StringBuffer();
            stringBuffer.append(String.format("**************************[  %s  ]**************************************\n", title));
            stringBuffer.append("访问路径: ").append(target).append("\n");
            stringBuffer.append("资源来源: ").append(source).append("\n");
            Splitter.on("#").omitEmptyStrings().trimResults().splitToList(content).forEach(line->{
                stringBuffer.append(line).append("\n\n");
            });
            stringBuffer.append("************************************************************************\n");
            return stringBuffer.toString();
        }
    }
}
